package com.sckj.springboot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                //指定构建api文档的详细方法：apiInfo()
        .apiInfo(apiInfo())
                .select()
                //指定生成api接口的包路径，把controller作为包路径，生成controller中所有接口
        .apis(RequestHandlerSelectors.basePackage("com.sckj.springboot.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /*
    * 构建api文档的详细信息
    * @return*/
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //设置标题
                .title("springboot集成swagger文档")
                //设置接口描述
                .description("跟老何一起学习Swagger")
                //设置联系方式
                .contact("hezhenhong"+"www.baidu.com")
                //设置版本
                .version("1.0")
                //构建
                .build();
    }
}
